function bindEmailCaptchaClick(){
   $("#captcha-btn").click(function (event){
    var $this = $(this);
    // 阻止默认事件
    event.preventDefault();

    var email = $("input[name='email']").val();
    $.ajax({
      url: '/auth/captcha/email?email='+email,
      method: 'GET',
      success: function (result){
        var code = result['code'];
        if (code == 200){
          var countdowm = 60;
          $this.off('click');
          var timer = setInterval(function (){
            $this.text(countdowm);
            countdowm -= 1;
            if (countdowm <= 0){
              clearInterval(timer);
              $this.text('获取验证码');
              bindEmailCaptchaClick();
            }
          }, 1000);
          alert('邮箱验证码已发送！');
        }else{
          alert(result['message']);
        }
      },
      fail: function (error) {
        console.log(error);
      }
    })
  });
}


// 整个网页都加载完毕后执行
$(function (){
  bindEmailCaptchaClick();
});